home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / gr564s.zip / SRC / MS / LOGINDOS.C < prev    next >
C/C++ Source or Header  |  1992-09-05  |  3KB  |  154 lines

  1. /* getlogin for Novell + DOS */
  2.  
  3. /* by Rich Braun @ Kronos, 1991/03/13 */
  4. /* further hacking by Paul Eggert and Frank Whaley */
  5.  
  6.     /* $Id: logindos.c,v 1.2 1992/01/06 03:18:25 eggert Exp $ */
  7.  
  8. #include <dos.h>
  9. #include <string.h>
  10. #include <process.h>
  11.  
  12. #pragma pack(1)
  13. #define MAXPATHNAMELEN 128
  14.  
  15. /* Invoke the Novell API.  */
  16. #define novell_API(function, args, results, regsin, regsout, segregs) ( \
  17.     (regsin).h.ah = (function), \
  18.     (regsin).x.si = (unsigned short)(args), \
  19.     (regsin).x.di = (unsigned short)(results), \
  20.     intdosx(&(regsin), regsout, segregs) \
  21. )
  22.  
  23.  
  24. /* system call definitions */
  25.  
  26. /* Get Connection Information E3(16) */
  27. struct _gcireq {
  28.     unsigned short len;
  29.     unsigned char func;
  30.     unsigned char number;
  31. };
  32. struct _gcirep {
  33.     unsigned short len;
  34.     unsigned long objectID;
  35.     unsigned short objecttype;
  36.     char objectname[48];
  37.     unsigned char logintime[7];
  38.     unsigned char reserved[39];
  39. };
  40.  
  41. /* Scan File Information E3(0F) */
  42. struct _sfireq {
  43.     unsigned short len;
  44.     unsigned char func;
  45.     unsigned short seq;
  46.     char handle;
  47.     unsigned char attrib;
  48.     unsigned char pathlen;
  49.     char path[MAXPATHNAMELEN];
  50. };
  51. struct _fileinfo {
  52.     unsigned char attrib;
  53.     unsigned char xattrib;
  54.     unsigned long size;
  55.     unsigned short cdate;
  56.     unsigned short adate;
  57.     unsigned long utime;
  58.     unsigned long ownerID;
  59.     unsigned long atime;
  60.     char res[56];
  61. };
  62. struct _sfirep {
  63.     unsigned short len;
  64.     unsigned short seq;
  65.     char filename[14];
  66.     struct _fileinfo info;
  67. };
  68.  
  69. /* Set File Information E3(10) */
  70. struct _setfireq {
  71.     unsigned short len;
  72.     unsigned char func;
  73.     struct _fileinfo info;
  74.     unsigned char handle;
  75.     unsigned char search;
  76.     unsigned char pathlen;
  77.     unsigned char path[MAXPATHNAMELEN];
  78. };
  79. struct _setfirep {
  80.     unsigned short len;
  81. };
  82.  
  83. /* Scan Directory for Trustees E2(0C) */
  84. struct _sdftreq {
  85.     unsigned short len;
  86.     unsigned char func;
  87.     unsigned char handle;
  88.     unsigned char seq;
  89.     unsigned char pathlen;
  90.     char path[MAXPATHNAMELEN];
  91. };
  92. struct _sdftrep {
  93.     unsigned short len;
  94.     char name[16];
  95.     unsigned long ctime;
  96.     unsigned long ownerID;
  97.     unsigned long trustee[5];
  98.     unsigned char rights[5];
  99. };
  100.  
  101. /* Scan Directory Information E2(02) */
  102. struct _sdireq {
  103.     unsigned short len;
  104.     unsigned char func;
  105.     unsigned char handle;
  106.     unsigned short seq;
  107.     unsigned char pathlen;
  108.     char path[MAXPATHNAMELEN];
  109. };
  110. struct _sdirep {
  111.     unsigned short len;
  112.     char name[16];
  113.     unsigned long ctime;
  114.     unsigned long ownerID;
  115.     unsigned char rights;
  116.     unsigned char res;
  117.     unsigned short dirnum;
  118. };
  119.  
  120. #pragma pack()
  121.  
  122.     char *
  123. getlogin()
  124. {
  125.     /* These are static because we assume segment register DS.  */
  126.     static struct _gcirep gcirep;
  127.     static struct _gcireq gcireq;
  128.  
  129.     union REGS r;
  130.     struct SREGS s;
  131.  
  132.     /* Load Get Connection Number function code.   */
  133.     r.x.ax = 0xDC00;
  134.     intdos(&r, &r);
  135.  
  136.     /*
  137.      * If the connection number is in range 1-100,
  138.      * invoke Get Connection Information to get the user name.
  139.      */
  140.     if (0 < r.h.al  &&  r.h.al <= 100) {
  141.         gcireq.len = sizeof(gcireq)-sizeof(gcireq.len);
  142.         gcireq.func = 0x16;
  143.         gcireq.number = r.h.al;
  144.         gcirep.len = sizeof(gcirep)-sizeof(gcirep.len);
  145.         segread(&s);
  146.         novell_API(0xE3, &gcireq, &gcirep, r, &r, &s);
  147.         if (r.h.al == 0) {
  148.             strlwr(gcirep.objectname);
  149.             return gcirep.objectname;
  150.         }
  151.     }
  152.     return 0;
  153. }
  154.